uint32_t count = 0;
uint16_t pwm = 0;
int val;

const int motorPin1 = 2;
const int motorPin2 = 4;
const int pwmPin = 5;

void countPulse() {
  count++;
}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  
  // pin 2, RISING edge
  attachInterrupt(0, countPulse, RISING);
  
  // Enable and direction pins
  pinMode(motorPin1, OUTPUT); // 2
  pinMode(motorPin2, OUTPUT);  //4
  motorrotate(50);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("PWM: ");
  Serial.println(pwm);
  Serial.print("count: ");
  Serial.println(count);
  count = 0;
  analogWrite(5, pwm);
  pwm = 100;
  
  delay(1000);

}

void motorrotate(uint8_t speed) { // code to control speed 
  
  digitalWrite(motorPin2, LOW); 
  analogWrite(pwmPin, speed); 
  digitalWrite(motorPin1,HIGH);
  
}


